package org.apache.lucene.ocean.database;

import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.ocean.TransactionSystem;
import org.apache.lucene.ocean.log.LogFileManager;
import org.apache.lucene.ocean.log.RecordHeader;
import org.apache.lucene.ocean.log.LogFileManager.RecordInfoBackwardIterator;

/**
 * Obtains transaction infos from the OceanDatabase 
 *
 */
public class GetTransactionsTask implements Task {
  public int num;
  
  public Object run(TransactionSystem transactionSystem) throws Exception {
    LogFileManager logFileManager = transactionSystem.getTransactionLog().getLogFileManager();
    RecordInfoBackwardIterator iterator = logFileManager.getRecordInfosBackwardIterator(null, true);
    int count = 0;
    List<Long> list = new ArrayList<Long>(num);
    while (iterator.hasPrevious() && count < num) {
      RecordHeader header = iterator.previous();
      list.add(header.id);
      count++;
    }
    return list;
  }
}
